#include <chrono>
#include <gtest/gtest.h>
#include <thread>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/internal/Buffer.h>
#include <vtkm/cont/TryExecute.h>

struct TestMetaData
{
  vtkm::Id Value = 1;
};
struct TestMetaData1
{
  vtkm::Id Value = -21;
  vtkm::Float32 v = 2.;
};

TEST(Buffer, buffer)
{
  vtkm::cont::internal::Buffer buffer;
  //std::cout << "IsAllocatedOnHost: " << buffer.IsAllocatedOnHost() << std::endl;

  TestMetaData data;
  buffer.SetMetaData<TestMetaData>(data);
  TestMetaData1 data1;
  buffer.SetMetaData<TestMetaData1>(data1);
  buffer.SetMetaData<int>(-2);

  //std::cout << "IsAllocatedOnHost: " << buffer.IsAllocatedOnHost() << std::endl;

  //EXPECT_EQ(buffer.GetMetaData<int>(), 1);
  //std::cout << "GetNumberOfBytes: " << buffer.GetNumberOfBytes() << std::endl;
  //vtkm::cont::Token token;
  //buffer.SetNumberOfBytes(100, vtkm::CopyFlag::Off, token);
  //std::cout << "GetNumberOfBytes: " << buffer.GetNumberOfBytes() << std::endl;
  //EXPECT_EQ(buffer.GetMetaData<int>(), 1);
  //buffer.IsAllocatedOnHost();
}

TEST(ArrayHandle, Allocate)
{
  //vtkm::cont::ArrayHandle<double> array;
  //static constexpr int array_size = 1000000000;
  //array.Allocate(array_size);
  //auto portal = array.WritePortal();
  ////auto a = portal.Get(0);
  //for (size_t i = 0; i < array_size; i++)
  //{
  //  portal.Set(i, 12.0);
  //}
  //std::cout << array.GetNumberOfValues() << std::endl;
  //std::cout << array.GetBuffers()[0].GetNumberOfBytes()<< std::endl;
  //
  //std::this_thread::sleep_for(std::chrono::seconds(20));

	vtkm::cont::TryExecute(
    [](auto v)
    {
      //std::cout << vtkm::cont::TypeToString(v) << std::endl;
      return true;
    });
}
